<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #a {
            width: 200px;
            height: 200px;
            background-color: #f00;
            margin: 100px;
            border: 1px solid #000;
            position: relative;
            overflow-y: scroll;
        }

        .a1 {
            width: 100px;
            height: 1000px;
            margin: 50px;
            border: 1px solid #000;
        }
    </style>
</head>

<body>

    <div id="a">
        <div class="a1"></div>
    </div>

    <script>

        // offsetLeft  盒子距离参照物的左边距  --- 盒子本身有没有定位无所谓
        // offsetTop   盒子距离参照物的上边距


        var oA1 = document.querySelector('.a1');
        console.log(oA1.offsetLeft);


    </script>

</body>

</html>